<?php

// +----------------------------------------------------------------------
// | Apprh.Shop
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.apprh.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// +----------------------------------------------------------------------
// | Author: 雲溪荏苒 <290648237@qq.com>
// +----------------------------------------------------------------------

namespace app\cms\controller;

use controller\HomeBase;


/**
 * 文章控制器
 * Class Article
 * @package app\cms\controller
 * @author 雲溪荏苒 <290648237@qq.com>
 * @date 2017/9/26
 */
class Article extends HomeBase
{

    public function index()
    {
        // 获取文章分类
        $articleClassList = D('cms_article_class')->getList(['show_in_nav' => 1]);
        $this->assign('articleClassList', $articleClassList);

        // 获取文章列表
        $condition['article_state'] = 3;
        if(I('ac_id')){
            $condition['article_class_id'] = I('ac_id');
        }
        $this->assign('ac_id', I('ac_id'));
        list($articleList, $articleTotal) = D('cms_article')->getList($condition);
        $this->assign('articleList', $articleList);
        $this->assign('articleTotal', $articleTotal);
//        dump($articleList);die;

        // 渲染分页
        $pageHtml = lay_page($articleTotal);
        $this->assign('page', $pageHtml);

        // SEO
        $this->assign('seo_title', '新闻中心_'.sysconf('cms_article_seo_title').'_'.sysconf('seo_title'));
        $this->assign('seo_keywords', sysconf('cms_article_seo_keywords').','.sysconf('seo_keywords'));
        $this->assign('seo_description', sysconf('cms_article_seo_desc').sysconf('seo_description'));

        return $this->fetch('');
    }

    public function show()
    {
        $articleId = I('article_id');

        // 获取文章分类
        $articleClassList = D('cms_article_class')->getList(['show_in_nav' => 1]);
        $this->assign('articleClassList', $articleClassList);

        // 获取新闻详情
        $articleInfo = D('cms_article')->getArticleDetail($articleId);
        $this->assign('articleInfo', $articleInfo);

        // 获取上一篇、下一篇文章
        list($previous, $next) = D('cms_article')->getFrontAfterArticles($articleId);
        $this->assign('previous', $previous);
        $this->assign('next', $next);

        // 文章访问量+1
        D('cms_article')->setViewInc($articleId);

        // SEO
        $this->assign('seo_title', $articleInfo['article_title'].'_新闻中心');
        $this->assign('seo_keywords', sysconf('cms_article_seo_keywords').','.sysconf('seo_keywords'));
        $this->assign('seo_description', msubstr($articleInfo['article_abstract'], 0, 150));

        return $this->fetch('');
    }
}
